package com.zhou.base.components.mp.ds.template.mapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zhou.base.components.mp.ds.annotation.DataColumn;
import com.zhou.base.components.mp.ds.annotation.DataPermission;
import com.zhou.base.components.mp.ds.template.entity.Comment;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * <p>
 * 评论 Mapper 接口
 * </p>
 *
 * @author zxf
 * @since 2023-10-28
 */
//@DataPermission({
//        @DataColumn(key = "deptName", value = "deptId"),
//        @DataColumn(key = "userName", value = "userId")
//})
public interface CommentMapper extends BaseMapper<Comment> {

    List<Comment> getCommentsByToId(@Param("toId") Long toId);

    /**
     * 测试错误的权限
     *
     * @param toId
     * @return
     */
    @DataPermission({
            @DataColumn(key = "userName1", value = "userId")
    })
    List<Comment> getCommentsByToIdWithErrorPermission(@Param("toId") Long toId);

    List<Comment> getCommentsByToIdWithIgnorePermission(@Param("toId") Long toId);

    @InterceptorIgnore(dataPermission = "1")
    List<Comment> getCommentsByToIdWithIgnorePermission1(@Param("toId") Long toId);

    @DataPermission({
            @DataColumn(key = "userName", value = "c.userId"),
            @DataColumn(key = "userName", value = "m.userId")
    })
    List<Comment> getComments1(@Param("toId") Long toId);


    @DataPermission({
            @DataColumn(key = "deptName", value = "deptId"),
            @DataColumn(key = "userName", value = "c.userId"),
            @DataColumn(key = "userName", value = "m.userId")
    })
    List<Comment> getCommentsWithNormPermission(@Param("toId") Long toId);

    /**
     * default上的注解不起效
     *
     * @return
     */

    default List<Comment> getComments() {
        return selectList(Wrappers.emptyWrapper());
    }

    @DataPermission({
            @DataColumn(key = {"userName", "deptName1"}, value = {"userId", "deptId"}),
    })
    List<Comment> selectList(@Param(Constants.WRAPPER) Wrapper<Comment> queryWrapper);


    @DataPermission({
            @DataColumn(key = {"userName", "deptName"}, value = {"c.userId", "deptId"}, sqlReplace = "1=1"),
    })
    List<Comment> getCommentsWithReplace(@Param("toId") Long toId);

    @DataPermission({
            @DataColumn(key = {"userName", "deptName"}, value = {"userId", "deptId"}, sqlReplace = "1=1"),
    })
    List<Comment> getCommentsWithReplace1(@Param("toId") Long toId);

    @DataPermission({
            @DataColumn(key = {"userName", "deptName"}, value = {"userId", "deptId"}, sqlReplace = "1=1"),
    })
    List<Comment> getCommentsWithReplace2(@Param("toId") Long toId);
}
